package com.huluobo.a2107monthdemo.category

import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.widget.LinearLayout
import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.huluobo.a2107monthdemo.R
import com.huluobo.a2107monthdemo.utils.ImageUtil

/**
 *  Created by LC on 2023/12/4.
 */
class CategoryChildAdapter(list: MutableList<CategoryBean>) :
    BaseQuickAdapter<CategoryBean, BaseViewHolder>(R.layout.item_category_child, list) {
    private var selectItemId = 14

    override fun convert(helper: BaseViewHolder, item: CategoryBean) {
        helper.setText(R.id.item_category_child_tv, item.category_name)
        ImageUtil.loadImage(context, item.category_icon.toString(), helper.getView(R.id.item_category_child_iv))

        helper.getView<LinearLayout>(R.id.item_category_child_ll).background =
            if (item.id == selectItemId) ColorDrawable(Color.RED) else null

        helper.getView<TextView>(R.id.item_category_child_tv).setTextColor(
            if (item.id == selectItemId) Color.WHITE else Color.BLACK
        )

    }

    fun setSelectItemPosition(itemId: Int) {
        selectItemId = itemId
        notifyDataSetChanged()
    }
}